package com.emergency.db.controller.item;

import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.db.domain.item.HugeItemStatus;
import com.emergency.db.service.item.HugeItemStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/hugeitem/status")
@CrossOrigin
public class HugeItemStatusController {
    @Autowired
    private HugeItemStatusService hugeItemStatusService;

    //保存
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody HugeItemStatus hugeItemStatus) {
        Long id = hugeItemStatusService.save(hugeItemStatus);
        return new Result(true, StatusCode.OK, "保存成功", id);
    }

    //查询单项
    @RequestMapping(value = "/search/{id}", method = RequestMethod.POST)
    public Result findById(@PathVariable("id") Long id) {
        HugeItemStatus hugeItemStatus = hugeItemStatusService.findById(id);
        return new Result(true, StatusCode.OK, "查询成功", hugeItemStatus);
    }

    //查询单项ByItem
    @RequestMapping(value = "/search/item/{id}", method = RequestMethod.POST)
    public Result findAllByItem(@PathVariable("id") Long id) {
        List<HugeItemStatus> hugeItemStatusList = hugeItemStatusService.findAllByItem(id);
        return new Result(true, StatusCode.OK, "查询成功", hugeItemStatusList);
    }

    //删除
    @RequestMapping(value = "/del/{id}", method = RequestMethod.POST)
    public Result delete(@PathVariable Long id) {
        hugeItemStatusService.delete(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    //删除byItem
    @RequestMapping(value = "/del/item/{id}", method = RequestMethod.POST)
    public Result deleteAllByItem(@PathVariable Long id) {
        hugeItemStatusService.deleteAllByItem(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    @RequestMapping(value = "list/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) {
        Page<HugeItemStatus> pageList = hugeItemStatusService.findList(searchMap, page, size);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }
}
